<?php
/**
 * DynaGrid - The PHP datagrid
 *
 * @package    DynaGrid
 * @author     $Author: keesschepers $
 * @version    $Id: Body.php 15 2011-02-15 17:07:57Z keesschepers $
 */

/**
 * Body part of the table <tbody>
 *
 */
class DynaGrid_HTML_Table_Body extends DynaGrid_HTML_Abstract {
	protected $tagname = 'tbody';
	protected $columns;
	public function __construct(DynaGrid_HTML_Table_Columns &$columns) {
		$this->columns = $columns;
	}	
	public function getHTML() {		
		try {
			foreach ($this->columns->datasource->getData() as $row) {				
				$this->innerHTML .= '<tr>';
				foreach ($this->columns->getColumns('body') as $column) {
					if($column->hasCallbackData()) {
						$this->innerHTML .= $column->getHTML($column->getCallbackData());
					} else {
						$this->innerHTML .= $column->getHTML($row[$column->name]);
					}
				}
				$this->innerHTML .= '</tr>';		
			}
		} catch (DynaGrid_NoRowsException $e) {
			$this->innerHTML .= '<tr>';
			$this->innerHTML .= '<td colspan="'.count($this->columns->getColumns('body')).'">'.$e->getMessage().'</td>';
			$this->innerHTML .= '</tr>';
		}
		return parent::getHTML();
	}
}